#Demo11.ps1
#Utilisation d'un appender SMTP
.\InitializeLG4N.ps1 
 
 #!!!!!!!  Change the email addresses !!!!!!!!!!!!!
$From="Log4Posh@Gmail.fr"
$To="Administrators@Gmail.US"
or $To="Administrators@Gmail.US,user2.@Yahoo.us"
$SMTPHost="smtp.google.com"

 #Configuration ? minima 
New-LogSmtpAppender -L "%date %-5level - %message%newline" `
                    -Name "Mailer" `
                    -Evaluator (New-LogLevelEvaluator "Fatal") `
                    -From $From `
                    -To $To `
                    -SMTPHost $SMTPHost `
                    -Subject "[$env:COMPUTERNAME]Fatal Error in $($MyInvocation.InvocationName) script."|`
    Enable-LogAppender|`
    Set-LogBasicConfigurator
$LogMail  = Get-LogLogger "SendMail"
 #Send 1 message, Now
$LogMail.Fatal("Fatal error detected.")   
#Title : [MyServername]Fatal Error in Demo11.ps1 script.
#body : 2009-02-15 10:09:03,515 FATAL - Fatal error detected. 

 #D?clare une propri?t? active globale
. .\PackageDebugTools.ps1
 Set-LogActiveProperty "CallStack" { $(ParseStack $(Get-CallStack)) }
 $DatePattern=(Get-UICulture).DateTimeFormat.ShortDatePattern -Replace "/","-"
 $LogPattern = "[%P{log4net:HostName}(Logger=%logger)]-%date{$DatePattern} %-5level %property{CallStack} - %message%newline"
 Update-LogLayout $LogMail.Logger.Parent.Appenders[0] $LogPattern

$Subject= "[$env:COMPUTERNAME]Fatal Error in function `$(`$MyInvocation.InvocationName)."

Function Une {
Deux }

Function Deux {
 $LogMail.Logger.Parent.Appenders[0].Subject= $ExecutionContext.InvokeCommand.ExpandString($Subject) 
 $LogMail.Fatal("Dans la fonction Deux")
#Title : [MyServername]Fatal Error in function Deux.
#body : [MyServername(Logger=SendMail)]-15-02-2009 FATAL une:Deux - Dans la fonction Deux 
}

Une
#suite dans Demo11-1.ps1
